#include "header/common.h"

int main(int argc, char *argv[])
{
  int sound,resolution,xsize,ysize,restart=1;
  SDL_Surface *screen,*background;
  int channel;			
  int audio_rate = 22050;			
  Uint8 audio_format = AUDIO_U8; 	
  int audio_channels = 1;			
  int audio_buffers = 512;
  system("clear");
  do
    {
      options(1,&sound,&resolution); 
      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1)
	{
	  printf("SDL kann nicht gestartet werden! / NO SDL INIT!:  %s\n", SDL_GetError());
	  exit(1);
	}
      if(resolution==1)
	{
	  xsize=640;ysize=480;
	  background = SDL_LoadBMP("image/640480/menubackground.bmp");
	}
      if(resolution==2)
	{
	  xsize=800;ysize=600;
	  background = SDL_LoadBMP("image/800600/menubackground.bmp");
	}  
      if(resolution==3)
	{
	  xsize=1024;ysize=768;
	  background = SDL_LoadBMP("image/1024768/menubackground.bmp");
	}  
      if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
	printf("Unable to initialize audio: %s\n", Mix_GetError());
	exit(1);
      }
      atexit(SDL_Quit);
      screen = SDL_SetVideoMode(xsize,ysize, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
      SDL_BlitSurface(background,NULL,screen,NULL);
      SDL_Flip(screen);
      if (screen == NULL) 
	{
	  printf("SDL laeuft nicht.../ Can't set video mode: %s\n", SDL_GetError());
	  exit(1);
	} 
      restart=menu(screen);     
      SDL_Quit;
      if(sound)play(0);
      Mix_CloseAudio(); 
      SDL_CloseAudio(); 
    }while(restart==2);
  return 0;
}
